// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class CLINICAL_HISTORY_CQU_I19 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("42 ORC",42)]
  	    [HL7Field(HL7Version.v27, 42, HL7Repeat.False, HL7Required.True,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("43 CLINICAL_HISTORY_DETAIL",43)]
  	    [HL7Field(HL7Version.v27, 43, HL7Repeat.True, HL7Required.False,"CLINICAL_HISTORY_DETAIL_CQU_I19")]
	    public CLINICAL_HISTORY_DETAIL_CQU_I19[] CLINICAL_HISTORY_DETAIL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("73 ROLE_CLINICAL_HISTORY",73)]
  	    [HL7Field(HL7Version.v27, 73, HL7Repeat.True, HL7Required.False,"ROLE_CLINICAL_HISTORY_CQU_I19")]
	    public ROLE_CLINICAL_HISTORY_CQU_I19[] ROLE_CLINICAL_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("83 CTI",83)]
  	    [HL7Field(HL7Version.v27, 83, HL7Repeat.True, HL7Required.False,"CTI")]
	    public CTI[] CTI {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			CLINICAL_HISTORY_DETAIL = ProcessGroupArray<CLINICAL_HISTORY_DETAIL_CQU_I19>(availableData, options, "CLINICAL_HISTORY_DETAIL");
			ROLE_CLINICAL_HISTORY = ProcessGroupArray<ROLE_CLINICAL_HISTORY_CQU_I19>(availableData, options, "ROLE_CLINICAL_HISTORY");
			CTI = PopSegmentParseAndCheckRequiredArray<CTI>(availableData, options, "CTI");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			CLINICAL_HISTORY_DETAIL_CQU_I19 testCLINICAL_HISTORY_DETAIL_CQU_I19 = new CLINICAL_HISTORY_DETAIL_CQU_I19();
			bool grpCCCLINICAL_HISTORY_DETAIL_CQU_I19 = (testCLINICAL_HISTORY_DETAIL_CQU_I19.CanConsume(availableData, options));
			if (IsRequired("CLINICAL_HISTORY_DETAIL", options.Version) || grpCCCLINICAL_HISTORY_DETAIL_CQU_I19) {
				return grpCCCLINICAL_HISTORY_DETAIL_CQU_I19;
			}
			ROLE_CLINICAL_HISTORY_CQU_I19 testROLE_CLINICAL_HISTORY_CQU_I19 = new ROLE_CLINICAL_HISTORY_CQU_I19();
			bool grpCCROLE_CLINICAL_HISTORY_CQU_I19 = (testROLE_CLINICAL_HISTORY_CQU_I19.CanConsume(availableData, options));
			if (IsRequired("ROLE_CLINICAL_HISTORY", options.Version) || grpCCROLE_CLINICAL_HISTORY_CQU_I19) {
				return grpCCROLE_CLINICAL_HISTORY_CQU_I19;
			}
			bool isCTI = availableData.StartsWith("CTI", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CTI", options.Version) || isCTI) {
				return isCTI;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "CLINICAL_HISTORY";
			}
        }

        static CLINICAL_HISTORY_CQU_I19() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(CLINICAL_HISTORY_CQU_I19));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CLINICAL_HISTORY_DETAIL != null && CLINICAL_HISTORY_DETAIL.Length > 0) {
			for (int i = 0; i < CLINICAL_HISTORY_DETAIL.Length; i++) {
				string segmentValue = CLINICAL_HISTORY_DETAIL[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ROLE_CLINICAL_HISTORY != null && ROLE_CLINICAL_HISTORY.Length > 0) {
			for (int i = 0; i < ROLE_CLINICAL_HISTORY.Length; i++) {
				string segmentValue = ROLE_CLINICAL_HISTORY[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (CTI != null && CTI.Length > 0) {
			for (int i = 0; i < CTI.Length; i++) {
				string segmentValue = CTI[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

